//
//  SheViewController.m
//  家范
//
//  Created by 吴军虎吴军虎 on 16/4/22.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "SheeViewController.h"
#import "SetupViewController.h"
#import "InputViewController.h"
#import "InputLogViewController.h"

#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height

@interface SheeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,retain) UIView *myheaderView;
@property (nonatomic,retain) UITableView *tableView;

@end

@implementation SheeViewController

-(void) viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
    self.tabBarController.tabBar.hidden=YES;
    self.title=@"设置";
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
     self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=LV;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=LV;
    _tableView.separatorStyle=UITableViewCellAccessoryNone;
    [self.view addSubview:_tableView];
    
    
    //退出登录
    UIButton *btn=[[UIButton alloc]init];
    btn.backgroundColor=GH;
    btn.layer.cornerRadius=5;
    [btn setTitle:@"退出登录" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font=[UIFont fontWithName:@"Arial" size:LOGINFONT *TEXTWEIGHT];
    [_tableView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(_tableView.mas_bottom).offset(1000/2 *AUTO_WIDTH);
        make.left.equalTo(self.view).offset(44/2 *AUTO_WIDTH);
        make.right.equalTo(self.view).offset(-44/2 *AUTO_WIDTH);
        make.height.mas_offset(78/2 *AUTO_HEIGHT);
    }];

    
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else{
        return 4;
    }
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50 *AUTO_WIDTH;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *dientifier=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:dientifier];
    if ( !cell ) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dientifier];
    }
    
    //箭头
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 9 *AUTO_WIDTH, 15 *AUTO_WIDTH)];
    imageView.image=[UIImage imageNamed:@"arrow"];
    cell.accessoryView=imageView;
    
    cell.textLabel.textColor = HS;
    cell.textLabel.font = [UIFont systemFontOfSize:14.0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //添加自定义分割线
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:224/255.0 alpha:1.0];
    [cell.contentView addSubview:view];
    if (indexPath.section == 0 || indexPath.row == 3) {
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(cell.contentView.mas_bottom).offset(0);
            make.left.equalTo(cell.mas_left).offset(0);
            make.size.mas_equalTo(CGSizeMake(ScreenW, 1));
        }];
    }else{
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(cell.contentView.mas_bottom).offset(0);
            make.left.equalTo(cell.mas_left).offset(10);
            make.size.mas_equalTo(CGSizeMake(ScreenW - 10, 1));
        }];
    }
    
    if (indexPath.section==0) {
        
        cell.textLabel.text=@"消息提醒";
        
    }else{
       
        if (indexPath.row ==0) {
            cell.textLabel.text=@"修改手机号码";
            
        }else if (indexPath.row ==1){
            cell.textLabel.text=@"修改密码";
        }else if (indexPath.row==2){
            cell.textLabel.text=@"意见反馈";
        }else{
           cell.textLabel.text=@"关于我们";
        }
    }
    
    return cell;
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 44/2 *AUTO_HEIGHT;
    
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
       
        SetupViewController *set=[[SetupViewController alloc]init];
        [self.navigationController pushViewController:set animated:YES];
    }else {
    
        if (indexPath.row ==0) {
            
            InputViewController  *put=[[InputViewController alloc]init];
            [self.navigationController pushViewController:put animated:YES];
        }else if (indexPath.row ==1){
           
            InputLogViewController *log=[[InputLogViewController alloc]init];
            [self.navigationController pushViewController:log animated:YES];
        }else{
        
            
            
        }
    }
}


//返回按钮
-(void) Back:(UIButton *) btn
{
    [self.navigationController popViewControllerAnimated:YES];
}


//退出按钮
-(void) btnAction:(UIButton*) btn
{
    NSLog(@"退出按钮退出按钮退出按钮");
}
@end
